package cn.jdy.plugins.service;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.hibernate.SQLQuery;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.jdy.common.constant.GlobalConstant;
import cn.jdy.framework.db.hibernate.BaseDao;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.framework.safe.SafeUtil;
import cn.jdy.framework.util.DateUtil;
import cn.jdy.framework.util.StringUtil;
import cn.jdy.platform.entity.ConfValue;
import cn.jdy.platform.service.ConfService;
import cn.jdy.plugins.entity.Info;
import cn.jdy.plugins.entity.Member;

/**
 * 会员管理实现类
 */
@Service
@DependsOn({"infoService", "confService"})
@Transactional
public class MemberService extends BaseDao<Member> {
	@Autowired
	private InfoService infoService;
	@Autowired
	private ConfService confService;
	@Autowired
	private CompanyService companyService;
	 
	
	public Member queryById(String id) {
		return super.findOne("id", id, "status", "1");
	}

	/**
	 * 查询会员信息
	 *
	 * @return
	 */
	public List<Member> query(Member entity) {
	  return query(entity, null, null);
	}

	/**
	 * 查询会员信息
	 *
	 * @return
	 */
	public List<Member> query(Member entity, String fromDate, String toDate) {
	  DetachedCriteria dc = createFilter(entity,fromDate,toDate);
    dc.addOrder(Order.desc("createTime"));
    return super.find(dc,entity.getiDisplayStart(),entity.getiDisplayLength());
	}
	 /**
	    * 查询是不是可以升级
	    * @return
	    */
	   public  void  addOrder(String uid){
	   	//订单号
			Map<String, Object> jsonMap = new HashMap<String, Object>();
				Member  member=this.find(uid);
				
			int zt=	this.queryzhiticount(uid);//统计下直推980个数
			int tt=	this.findgaojicount(uid);//统计下我的粉丝980个数
			int ff=	this.findcheckcount(uid);//统计下我的粉丝个数
			int zz=	this.findyunyingscount(uid);//统计下我的运营商个数
			
	 //用户等级   0运营商，1超级会员，2普通会员,3 初级代理，4 高级代理，5是1星运营商，6是2星运营商，7是3星运营商,8是4星运营商,9是5星运营商

				
			 if(member.getUserLevel().equals("4")){//高代升级
				 if(ff>=100&&zt>=10&&tt>=20){
					 member.setUserLevel("0");
				
					 List<Map<String,Object>> list =	queryshangjin(member.getId());
					 for (int i = 0; i < list.size(); i++) {
						String id= (String) list.get(i).get("id");
						Member mdid=find(id);
					String[] dlist=mdid.getTdlist().split(id);
					String tdlist="";
					if(dlist.length>1){
						tdlist=member.getId()+","+dlist[1];
					}else{
						tdlist=member.getId();
					}
						mdid.setTdlist(tdlist);
						mdid.setTuandui(member.getId());
						 update(mdid);
					}
					 member.setTuandui("");
					 this.update(member);
				 }
			 } else if(member.getUserLevel().equals("0")){//升级1星
				 if(zz>=1){
					 member.setUserLevel("5");
					 this.update(member);
				 }
			 }else if(member.getUserLevel().equals("5")){//升级1星
				 if(zz>=2){
					 member.setUserLevel("6");
					 this.update(member);
				 }
			 }else if(member.getUserLevel().equals("6")){//升级2星
				 if(zz>=5){
					 member.setUserLevel("7");
					 this.update(member);
				 }
			 }else if(member.getUserLevel().equals("7")){//升级3星
				 if(zz>=10){
					 member.setUserLevel("8");
					 this.update(member);
				 }
			 }else if(member.getUserLevel().equals("8")){//升级3星
				 if(zz>=20){
					 member.setUserLevel("9");
					 this.update(member);
				 }
			 }
	   }
	/**
	 * 首页：查询审核通过的商机(包括审核通过，下架和已删除)
	 *
	 * @return
	 */
	public Long count(Member entity, String fromDate, String toDate) {
	  DetachedCriteria dc = createFilter(entity,fromDate,toDate);
		return super.count(dc);
	}

	/**
	 * 拼装条件
	 *
	 * @param entity
	 * @param page
	 * @return
	 */
	private DetachedCriteria createFilter(Member entity, String fromDate, String toDate) {
		DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
		if(StringUtil.isNotEmpty(entity.getKeywords())) {
		  if(StringUtil.isNotEmpty(entity.getKeyType())) {
		    dc.add(Restrictions.like(entity.getKeyType(),"%"+entity.getKeywords().trim()+"%"));
		  }
		}
		if(StringUtil.isNotEmpty(entity.getStatus())) {
		  dc.add(Restrictions.eq("status", entity.getStatus()));
		}
		if(StringUtil.isNotEmpty(entity.getUserType())) {
		  dc.add(Restrictions.eq("userType", entity.getUserType()));
		}
		if(StringUtil.isNotEmpty(entity.getTdlist())) {
			   Restrictions.like("tdlist", entity.getTdlist(), MatchMode.ANYWHERE);
			}
 
		if(fromDate != null && fromDate.length() > 0 && toDate != null && toDate.length() > 0){
		  dc.add(Restrictions.between("createTime", fromDate, toDate));
		}else if(fromDate != null && fromDate.length() > 0){
		  dc.add(Restrictions.gt("createTime", fromDate));
		}else if(toDate != null && toDate.length() > 0){
		  dc.add(Restrictions.lt("createTime", toDate));
		} 
		return dc;
	}
	public List<Member> queryxingyun() {
		StringBuilder sql = new StringBuilder("select * from  member  where 1=1 and  (userLevel =5 or  userLevel =6 or  userLevel =7 or  userLevel =8 or  userLevel =9)  ");
		return super.em().createSQLQuery(sql.toString()).list();
	}

	public List<Map<String,Object>> queryyueebao() {
	    List<Map<String,Object>> list=new  ArrayList<Map<String,Object>>();
		StringBuilder sql = new StringBuilder("select  id from member WHERE money>=100");
	      SQLQuery sqlQuery = em().createSQLQuery(sql.toString());
	    	 // 将查询寻结果转换为Map格式，解决多表查询或零散字段查询 映射取值问题
	    	      sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
				 list= sqlQuery.list();
		return list;
	}
	/*查看我下面全部*/
	public List<Map<String,Object>> queryshangjin(String uid) {
	
			    List<Map<String,Object>> list=new  ArrayList<Map<String,Object>>();
		    try {
				String allSql=" select id,headImg,userLevel,mobile from  member  where 1=1 and  tdlist  like '%"+uid+"%'  ";
		    	      SQLQuery sqlQuery = em().createSQLQuery(allSql);
		    	 // 将查询寻结果转换为Map格式，解决多表查询或零散字段查询 映射取值问题
		    	      sqlQuery.setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP);
					 list= sqlQuery.list();
			      return  	 list;
			    } catch (Exception e) {
			      BaseLog.e(this.getClass(), "查询异常！", e);
			    }
			return list;
	}
	/*统计下直推980个数*/
	public int queryzhiticount(String uid){
 
				String allSql=" select count(1)  from member  where 1=1 and  fid='"+uid+"' and userLevel=4 ";
			SQLQuery query = super.em().createSQLQuery(allSql);
			
			return Integer.parseInt(String.valueOf(query.uniqueResult()));
	}
	/**
	 *统计下我的粉丝980个数
	 *
	 * @param username
	 * @return
	 */
	public int findgaojicount(String uid) {
		SQLQuery query = super.em().createSQLQuery("select count(1) from  member  where 1=1 and userLevel=4   and   tdlist  like '%"+uid+"%'  ");

		return Integer.parseInt(String.valueOf(query.uniqueResult()));
	}
	
	/**
	 *统计下我的粉丝运营商个数
	 *
	 * @param username
	 * @return
	 */
	public int findyunyingscount(String uid) {
		SQLQuery query = super.em().createSQLQuery("select count(1) from  member  where 1=1 and userLevel=0   and   tdlist  like '%"+uid+"%'  ");

		return Integer.parseInt(String.valueOf(query.uniqueResult()));
	}
			/**
			 * 查询我的粉丝个数
			 *
			 * @param username
			 * @return
			 */
			public int findcheckcount(String username) {
				SQLQuery query = super.em().createSQLQuery("select count(1) from  member  where 1=1 and  tdlist  like '%"+username+"%'  ");
		
				return Integer.parseInt(String.valueOf(query.uniqueResult()));
			}
	
	public List<Member> queryByKeyword(String usertype, String keyword, String keyType, String fromDate, String toDate) {
		StringBuilder sql = new StringBuilder("select t2.id,userName,mobile,password,t2.email," +
				"signature,photo,birthday,sex,country,longitude,latitude,createTime,lastLoginDate," +
				"userType,status,approve,score,money,realname,cardNum,cardImgUrl,province,city," +
				"district,areaCode,telPhone,t2.companyName,job,personalLocation,companyLocation" +
				" from `company` t1 right join `member` t2 on t2.`id` = t1.`userid`");
		if(keyword != null && keyword.length() > 0) {
			sql.append(" where ");
			switch(keyType) {
				case "":
					sql.append(" INSTR(T2.username, '").append(keyword).append("')>0").append(" OR INSTR(T2.mobile, '").append(keyword).append("')>0");
					break;
				case "1":
					sql.append(" INSTR(T2.username, '").append(keyword).append("')>0");
					break;
				case "2":
					sql.append(" INSTR(T2.mobile, '").append(keyword).append("')>0");
					break;
			}
		}

		if(fromDate != null && fromDate.length() > 0) {
			sql.append(sql.indexOf("where") > 0 ? " AND " : " where ");
			sql.append(" createTime >= date_format('").append(fromDate).append("','%Y-%m-%d %H:%i:%s')");
		}

		if(toDate != null && toDate.length() > 0) {
			sql.append(sql.indexOf("where") > 0 ? " AND " : " where ");
			sql.append(" createTime <= date_format('").append(fromDate).append("','%Y-%m-%d %H:%i:%s')");
		}
		return super.em().createSQLQuery(sql.toString()).list();
	}


	/**
	 * 更新会员信息
	 *
	 * @param id
	 * @return flag
	 * @throws SQLException
	 * @description:
	 */
	public boolean updateMoney(String id, Long confId) {
		if(id == null || id.length() == 0 || confId == null || confId == 0) return false;
		ConfValue confValue = confService.find(confId);
		if(confValue == null || confValue.getValue1() == null) return false;
		String[] value = confValue.getValue1().split(",");
		int singleValue = Integer.parseInt(value[0]);
		if(singleValue <= 0) return false;

		String context = confValue.getValue0();
		int jf = context.indexOf("积分");
		int sm = context.indexOf("S币");
		Member member = super.find(id);
		if(jf>-1 && sm>-1) {
			if(jf > sm) {
				member.setScore(member.getScore() + Integer.parseInt(value[1]));
				member.setMoney(member.getMoney() + Integer.parseInt(value[0]));
			}else {
				member.setScore(member.getScore() + Integer.parseInt(value[0]));
				member.setMoney(member.getMoney() + Integer.parseInt(value[1]));
			}
			context = context.replaceFirst("%d", value[0]).replaceFirst("%d", value[1]);
		}else if(jf > -1) {
			member.setScore(member.getScore() + singleValue);
			context = context.replaceFirst("%d", value[0]);
		}else if(sm > -1) {
			member.setMoney(member.getMoney() + singleValue);
			context = context.replaceFirst("%d", value[0]);
		}else return false;

		try {
		  super.update(member);
		  //如果奖励成功，则发送消息提醒用户
			Info info = new Info();
			info.setType("1");
			info.setTitle(confValue.getRemark());
			info.setContext(context);
			info.setUserid(id);
			infoService.saveOrUpd(info);
		} catch(Exception e) {
			BaseLog.e(getClass(), "发送'系统奖励S币'系统消息异常！", e);
		}
		return true;
	}

	/**
	 * 更新会员信息
	 *
	 * @param id
	 * @return flag
	 * @throws SQLException
	 * @description:
	 */
	public void updateMoneyWithInfo(String id, int money, String title, String context) throws SQLException {
		if(id == null || id.length() == 0 || money <= 0){
		  return ;
		} 
		super.update(id, "money", money);
		Member member = super.find(id);
		member.setMoney(member.getMoney() + money);
		if(StringUtil.isNotEmpty(title)) {
			try {
			  super.update(member);
				Info info = new Info();
				info.setType("1");
				info.setTitle(title);
				info.setContext(context);
				info.setUserid(id);
				infoService.saveOrUpd(info);
			} catch(Exception e) {
				BaseLog.e(getClass(), "发送'系统奖励S币'系统消息异常！", e);
			}
		}
	}

	/**
	 * 更新会员信息
	 *
	 * @param id
	 * @return flag
	 * @throws SQLException
	 * @description:
	 */
	public void updateLoginDate(String id) throws SQLException {
	  super.update(id, "lastlogindate", DateUtil.getCurrentTime());
	}

	/**
	 * 修改会员手机号
	 *
	 * @param bo
	 * @return flag
	 * @description:
	 */
	public void updateMobile(Member bo) {
	  super.update(bo.getId(), "mobile", bo.getMobile());
	}

	/**
	 * 修改会员头像
	 *
	 * @param bo
	 * @return flag
	 * @description:
	 */
	public void updateForeImg(Member bo) {
	  super.update(bo.getId(), "photo", bo.getPhoto());
	}

	/**
	 * 批量更新会员信息
	 *
	 * @param ids
	 * @return flag
	 * @description:
	 */
	public String updateBatch(String ids, int type, String value) throws SQLException {
		String result = null;
		List<String> list = Arrays.asList(ids.split(","));
		for(String s : list) {
//			int id = Integer.parseInt(s);
			String id = s;
			switch(type) {
				case 1:
				  super.update(id, "money", Integer.parseInt(value));
					break;
				case 3:
					super.delete(id);
					break;
				case 4:
				  super.update(id, "status", "1");
					break;
				case 5:
				  super.update(id, "status", "0");
					break;
				case 6:
					if(super.update(id, "approve", "1")>0)
						this.updateMoney(s, GlobalConstant.SMONEY_APPROVED);
					break;
				case 7:
				  super.update(id, "approve", "2");
					break;
				case 8:
					result = String.valueOf(Math.random()).substring(2,8);
					super.update(id, "password", SafeUtil.md5(result).substring(8, 16));
					break;
				default:
					break;
			}
		}
		return result;
	}

	/**
	 * : 会员管理密码重置
	 *
	 * @return Boolean
	 * @description: 会员管理密码重置
	 * @author: wangbo
	 * @date: 2013-10-15 16:53
	 */
	public Boolean updResetPwd(Member entity) {
		return super.update(entity.getId(), "password", entity.getPassword())>0;
	}

	/**
	 * 根据用户名查找用户
	 *
	 * @param username
	 * @return
	 */
	public Member findMemberByUsername(String username) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  dc.add(Restrictions.or(Restrictions.eq("userName", username),Restrictions.eq("mobile", username)));
	  return super.findOne(dc);
	}

	
	
	/**
	 * 查下今日总订单
	 *
	 * @param username
	 * @return
	 */
	public Double findcheckDecimal() {
	

		  String sql ="select ROUND(SUM(total),2) from crateorder WHERE to_days(createTime) = to_days(now()) and  zfStatus=1 ";
		  SQLQuery query = super.em().createSQLQuery(sql);
		  //BaseDao
		
		  return (Double)query.uniqueResult();
	}
	
	
	/**
	 * 查下今日期权分红
	 *
	 * @param username
	 * @return
	 */
	public Double findcheckqquan(String uid) {
	

		  String sql ="SELECT ROUND(SUM(total),2) from maidjqfhcdb WHERE to_days(createTime) = to_days(now())  and  memberid=  ? ";
		  SQLQuery query = super.em().createSQLQuery(sql);
		  query.setParameter(0, uid);
		  
		  return (Double)query.uniqueResult();
	}
	
	/**
	 * 根据用户名查找用户
	 *
	 * @param username
	 * @return
	 */
	public int findcheckUsername(String username) {
		SQLQuery query = super.em().createSQLQuery("select count(1) from member m ,confvalue c  where m.username = ? or (c.typeid =16 and c.value0 = ?) or m.mobile = ?");
		query.setParameter(0, username);
		query.setParameter(1, username);
		query.setParameter(2, username);
		return Integer.parseInt(String.valueOf(query.uniqueResult()));
	}
	/**
	 * 根据用户名查找手机号
	 *
	 * @param username
	 * @return
	 */
	public int findcheckUseropen(String username) {
		SQLQuery query = super.em().createSQLQuery("select count(1) from member   where  mobile = ?");
		query.setParameter(0, username);

		return Integer.parseInt(String.valueOf(query.uniqueResult()));
	}
	
	/**
	 * 根据用户名邀请码是否被注册
	 *
	 * @param yqm
	 * @return
	 */
	public  int findcheckUseryqm(String yqm) {
		SQLQuery query = super.em().createSQLQuery("select count(1) from member   where  myyqm = ?");
		query.setParameter(0, yqm);
		return Integer.parseInt(String.valueOf(query.uniqueResult()));
	}
	/**
	 * 根据用户名查找用户
	 *
	 * @param mobile
	 * @return
	 */
	public Long findcheckUsermobile(String mobile) {
	  DetachedCriteria dc = DetachedCriteria.forClass(entityClass);
	  dc.add(Restrictions.or(Restrictions.eq("userName",mobile),Restrictions.eq("mobile",mobile)));
	  return super.count(dc);
	}

	/**
	 * 保存用户
	 *
	 * @param member
	 * @return
	 */
	public Member saveMember(Member member) {
		String pwd = member.getPassword();
		member.setPassword(SafeUtil.md5(pwd).substring(8, 16));
		member.setStatus("0");
		member.setPhoto("/images/no-img_mid_.jpg");
		member.setScore(0);
		member.setMoney(0);
	
		String yqm=generateString(6);
		int oep=findcheckUseryqm(yqm);
		if(oep> 0){ //如果有重复
			  yqm=generatezmString(6);
		} 
	 
		char fir = yqm.charAt(0);
		String de=fir+"";
		if(de.equals("0")){
			  StringBuilder sb = new StringBuilder(yqm);
			  sb.replace(0, 1, "11");
			  yqm=sb.toString();
		}
		//判断是否有上级码
		if(StringUtil.isNotEmpty(member.getSjyqm())){
			Member mb=findOne("myyqm",member.getSjyqm());
			if(mb!=null){
				  if(!StringUtil.isEmpty(mb.getTuandui())&&mb.getUserLevel().equals("0")){
						member.setTuandui(mb.getTuandui()); 
						Member mber=this.find(mb.getTuandui());
						if(StringUtil.isNotEmpty(mber.getFans())){
							mber.setFans((Integer.valueOf(mber.getFans())+1)+"");
						}else{
							mber.setFans("1");
						}
						update(mber);
				  }else{
					  member.setTuandui(mb.getId());
						if(StringUtil.isNotEmpty(mb.getFans())){
							mb.setFans((Integer.valueOf(mb.getFans())+1)+"");
						}else{
							mb.setFans("1");
						}
						update(mb);
				  }
				
		
					
				  if(!StringUtil.isEmpty(mb.getTdlist())){
						member.setTdlist(mb.getTdlist()+","+mb.getId()); 
				  }else{
					  member.setTdlist(mb.getId());
				  } 
				  
				member.setFid(mb.getId());
			//	member.setFid(mb.getId())
				if(StringUtil.isNotEmpty(mb.getFans())){
					mb.setFans((Integer.valueOf(mb.getFans())+1)+"");
				}else{
					mb.setFans(1+"");
				}
			}
		
		
		}
		member.setUserLevel("2");
		member.setMyyqm(yqm);
		member.setCreateTime(DateUtil.getCurrentTime());
		member.setApprove("1");
		save(member);
		try {
			Info info = new Info();
			info.setType("1");
			info.setTitle("恭喜您注册成功！");
			info.setContext(confService.findConfVal(String.valueOf(GlobalConstant.TYPE_MSG), "reg_S"));
			info.setUserid(member.getId());
			infoService.saveOrUpd(info);
		} catch(Exception e) {
			BaseLog.e(getClass(), "forSaveRegisterMember", e);
		}
		return member;
	}

	/**
	 * 修改会员密码
	 *
	 * @param id
	 * @param attr
	 * @param value
	 * @return
	 */
	public boolean updatepwd(String mobile, String password) {
	  SQLQuery query = super.em().createSQLQuery("update member set password = ? where mobile = ?");
	  query.setParameter(0, password);
	  query.setParameter(1, mobile);
	  return query.executeUpdate() > 0;
	}
	
	/**
	 * 公司的联系方式
	 * @return
	 */
  public String getMobile(){
    String sql = "select mobile from member where companyId = ?1 and userType=1";//公司类型
    SQLQuery query = super.em().createSQLQuery(sql);
    return (String)query.uniqueResult();
  }
  
  /**
	 * 昨日积分
	 * @return
	 */
public Double getzuojifen(String time,String id){
  String sql = "select ROUND(sum(total),2) as zs  from pointrecord where str_to_date(createTime, '%Y-%m-%d')=? and memberid=?";//公司类型
  SQLQuery query = super.em().createSQLQuery(sql);
  //BaseDao
	query.setParameter(0, time);
	query.setParameter(1, id);
  return (Double)query.uniqueResult();
}


/**
	 *今日推广奖励
	 * @return
	 */
public Double getjtgjl(String id){
String sql = "SELECT ROUND(SUM(fendtotal),2) from maid WHERE to_days(createTime) = to_days(now()) and  wermemberid=?";//公司类型
SQLQuery query = super.em().createSQLQuery(sql);
//BaseDao
	query.setParameter(0, id);

return (Double)query.uniqueResult();
}
/**
	 * 累积积分
	 * @return
	 */
public Double getliejijifen(String id){
String sql = "select ROUND(sum(total),2) as zs  from pointrecord where memberid=? ";//公司类型
SQLQuery query = super.em().createSQLQuery(sql);
query.setParameter(0, id);
//BaseDao
return (Double)query.uniqueResult();
}
 

/**
 * 今日新增提现
 * @return
 */
public Double getjinritx(){
String sql = "SELECT ROUND(SUM(applyCash),2) from applycash WHERE to_days(createTime) = to_days(now()) and status=1 ";// 
SQLQuery query = super.em().createSQLQuery(sql);

//BaseDao
return (Double)query.uniqueResult();
}


/**
 * 今日分佣
 * @return
 */
public Double gejinrifenyong(){
String sql = "SELECT  ROUND(SUM(fendtotal),2) from maid WHERE to_days(createTime) = to_days(now())   ";
SQLQuery query = super.em().createSQLQuery(sql);

//BaseDao
return (Double)query.uniqueResult();
}
  
  public static String randomUUID() {  
      return UUID.randomUUID().toString().replace("-", "");  
  } 
  /** 
   * 返回一个定长的随机字符串(只包含数字) 
   *  
   * @param length 
   *            随机字符串长度 
   * @return 随机字符串 
   */  
  public static String generateString(int ed){  
	    int  maxNum = 36;  
	    int i;  
	    int count = 0;  
	    char[] str = {  '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };      
	    StringBuffer pwd = new StringBuffer("");  
	    Random r = new Random();  
	    while(count <ed){  
	     i = Math.abs(r.nextInt(maxNum));     
	     if (i >= 0 && i < str.length) {  
	      pwd.append(str[i]);  
	      count ++;  
	     }  
	    }  
	    return pwd.toString();  
	  }  
  
  /** 
   * 返回一个定长的随机字符串( 包含数字和字母) 
   *  
   * @param length 
   *            随机字符串长度 
   * @return 随机字符串 
   */  
  public static String generatezmString(int ed){  
	    int  maxNum = 36;  
	    int i;  
	    int count = 0;  
	    char[] str = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',  
	            'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',  
	            'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };  
	    StringBuffer pwd = new StringBuffer("");  
	    Random r = new Random();  
	    while(count <ed){  
	     i = Math.abs(r.nextInt(maxNum));     
	     if (i >= 0 && i < str.length) {  
	      pwd.append(str[i]);  
	      count ++;  
	     }  
	    }  
	    return pwd.toString();  
	  }  
 
 public static void main(String[] args) {
		String str = "adadsauo";//定义一个字符串
		char fir = str.charAt(0);
		System.out.println(fir+"");
}
}
